﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="categorylist.aspx.cs" Inherits="UI.system.page.product.categorylist" %>
<%@ Import Namespace="Model" %>
<%@ Import Namespace="DAL" %>
<%@ Import Namespace="Common" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="/js/jquery.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/js/md5.js"></script>
    <script src="/js/swfupload.js"></script>
    <script src="/system/js/admin.js"></script>
    <script src="/system/layui/layui.js"></script>
    <link rel="stylesheet" href="/system/layui/css/layui.css">
    <link rel="stylesheet" href="/system/css/iframe.css">
    <style>
        td img{width:28px; height:28px; float:left; object-fit:cover}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="layer-toolbar">
        <div class="layer-toolbar-left">
        <%=MenuDAL.Power("Save") %>
        </div>
        <div class="layer-toolbar-right">
            <input id="keyword" type="text" name="title" placeholder="分类名称" autocomplete="off" class="layui-input" value=""  style="width:150px;" onkeyup='CRM.Enter("#search")'>
            <a id="search" class="layui-btn layui-btn-small layui-btn-normal" onclick="Search()">搜索</a>
            <a class="layui-btn layui-btn-small" onclick="Search()">刷新</a>
        </div>
    </div>
    <div id="iframe" class="layer-iframe">
    <table class="layui-table" lay-data="{id:'mytable', page:false, loading:true, height:'full-90'}">
      <thead>
        <tr>
          <th lay-data="{width:200, templet:'<div>{{# if(d.ParentID==0){ }}  <strong>{{d.Name}}</strong>  {{# }else{ }} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{d.Name}} {{# }}}</div>'}">分类名称</th>
          <th lay-data="{width:100,templet:'<div><img src=\'{{d.Img}}\'/></div>'}">分类图标</th>
          <th lay-data="{width:100,templet:'<div><input class=\'layui-input tdtext\' value=\'{{d.Sort}}\' onblur=ReSort(this,{{d.ID}},\'category\') /></div>'}">显示顺序</th>
          <th lay-data="{width:0}"></th>
          <th lay-data="{width:160, fixed:'right', templet:'#handler'}">操作</th>
        </tr>
      </thead>
    </table>
    <script type="text/html" id="handler">
        <%=MenuDAL.Powers("Edit,Delete") %>
        {{# if(d.ParentID==0){ }}
        <%=MenuDAL.Powers("Child") %>
        {{# } }}
    </script>
    </div>
    </form>
    <script>
        layui.use(["form", "table"], function () {
            var $ = layui.jquery, form = layui.form;
            table = layui.table;
            Init_Pager();
        });

        function Init_Pager() {
            var data = {};
            data.act = "Find_Category";
            data.keyword = $("#keyword").val();
            data.sign = GetSign(data.act);
            table.reload('mytable', {
                url: '/tools/Admin.ashx',
                loading: true,
                where: data
            });
        };

        function Save(o,id) {
            Ajax.Get("/system/page/product/categoryadd.aspx?id=" + id, function (html) {
                var title = id == 0 ? "新增" : "修改";
                window.parent.LayerBox.Show(title + "分类", html, "400px", "340px", null, function (form) {
                    var data = form;
                    data.act = "Save_Category";
                    data.id = id;
                    data.parentid = window.parent.$("#parentid").attr("parentid");
                    data.img = window.parent.$(".img_container img").attr("src");
                    data.sign = GetSign(data.act);
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                LayerBox.Close.ByAll();
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
                var upload = new window.parent.Upload_File("upload_file_o");
                upload.swfu.handle = "upload_file_o";
            });
        };
        function Child(o, id) {
            Ajax.Get("/system/page/product/categoryadd.aspx?id=0&parentid=" + id, function (html) {
                window.parent.LayerBox.Show("新增分类", html, "400px", "340px", null, function (form) {
                    var data = form;
                    data.act = "Save_Category";
                    data.id = 0;
                    data.parentid = id;
                    data.img = window.parent.$(".img_container img").attr("src");
                    data.sign = GetSign(data.act);
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                LayerBox.Close.ByAll();
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
                var upload = new window.parent.Upload_File("upload_file_o");
                upload.swfu.handle = "upload_file_o";
            });
        };
        function Delete(o, id) {
            LayerBox.Confirm("您确定要删除吗？", function () {
                Delete_Table(o, id, "Delete_Category");
            });
        };
</script>
</body>
</html>
